Assets
Adding assets to a project involves following steps:
To add assets to your project, place the assets files in a
src/static/images
directory within your project.To serve a assets file in Express, use the express.static middleware to specify the directory containing your asset files. For example:
server/server.js
const express = require("express")
const path = require("path")
// Server middlewares are added here.
export function addMiddlewares(app) {
app.use("/assets", express.static(path.join(__dirname, `../src/static/images`)),)
}
This assumes your assets files are stored in the "src/static/images" directory.
- You can use your assets in client code by adding prefex
/assets/
before your asset name.
<img src={"/assets/index.svg"}/>